//
//  ConnectUSPage.swift
//  Casecord
//
//  Created by baozi on 2024/1/10.
//

import SwiftUI

struct ConnectUSPage: View {
    @Environment(\.presentationMode) private var presentationMode
    
    @State private var text: String = ""
    @FocusState var textFocused: Bool
    
    @State private var email: String = ""
    @FocusState var emailFocused: Bool
    
    @Binding var isShow: Bool
    
    var body: some View {
        VStack {
            Text("Send us suggestion to help us build this app better.")
                .foregroundStyle(Theme.color.primaryBackgroundColor)
                .font(.system(size: 20))
                .fontWeight(.bold)
                .paddingBottom(10)
            Text("Email")
                .foregroundStyle(Theme.color.primaryBackgroundColor)
                .font(.system(size: 16))
                .fontWeight(.bold)
                .frame(maxWidth: .infinity, alignment: .leading)
                .paddingBottom(5)
            TextField(
                "",
                text: $email,
                prompt:
                    Text("Enter Your Email")
            )
            .foregroundStyle(Theme.color.primaryBackgroundColor)
            .textInputAutocapitalization(.never)
            .autocorrectionDisabled()
            .focused($emailFocused)
            .paddingBottom(10)
            
            Text("Suggestion")
                .foregroundStyle(Theme.color.primaryBackgroundColor)
                .font(.system(size: 16))
                .fontWeight(.bold)
                .frame(maxWidth: .infinity, alignment: .leading)
                .paddingBottom(5)
            TextField(
                "",
                text: $text,
                prompt:
                    Text("Enter Your Suggestion")
            )
            .foregroundStyle(Theme.color.primaryBackgroundColor)
            .textInputAutocapitalization(.never)
            .autocorrectionDisabled()
            .focused($textFocused)
            .paddingBottom(20)
            
            Button {
                guard email.isEmail else {
                    ToastManager.show(text: "Emial is a unuseful")
                    return
                }
                guard text.count > 0 else {
                    ToastManager.show(text: "Suggestion can't be null")
                    return
                }
                withAnimation {
                    isShow = false
                }
                ToastManager.show(text: "Thank you for your suggestions. We will carefully study and discuss whether to adopt it.")
            } label: {
                Text("Submit")
                    .foregroundStyle(.white)
                    .font(.system(size: 20))
                    .fontWeight(.bold)
                    .paddingHorizontal(20)
                    .paddingVerticol(10)
                    .withCapsuleBg(colors: [Theme.color.primaryBackgroundColor])
            }
        }
        .makeDismissAlert(show: $isShow)
    }
}

#Preview {
    ConnectUSPage(isShow: .constant(true))
}
